from django.test import TestCase
from .models import Student


class StudentModelTests(TestCase):
    @classmethod
    def setUpTestData(cls):
        """setUpTestData: Run once to set up non-modified data for all class methods."""
        # 创建一些测试数据
        cls.student = Student.objects.create(name='Test Student', sex='M', age=20, address='Test Address',
                                             enter_date='2023-09-01')

    def test_student_name_label(self):
        """测试Student的name字段的verbose_name属性"""
        field_label = self.student._meta.get_field('name').verbose_name
        self.assertEqual(field_label, '学生姓名')

    def test_student_creation(self):
        """测试学生记录是否成功创建"""
        self.assertTrue(Student.objects.exists())

    def test_student_str_representation(self):
        """测试模型的字符串表示形式"""
        self.assertEqual(str(self.student), 'Test Student')

    def test_age_greater_than_zero(self):
        """测试年龄是否大于零"""
        self.assertGreater(self.student.age, 0)
